﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;


namespace ComicReader.Model
{
    public interface IPageDataService
    {
        List<PageData> List();
        void Load(FileInfo fileInfo);
    }

    public class PageDataService : IPageDataService, INotifyPropertyChanged
    {
        private readonly IPageRepository PageRepository;

        public PageDataService()
        {
            PageRepository = new ZippedPageRepository();
        }


        public void Load(FileInfo fileInfo)
        {
            AssignPageDataRepository(fileInfo);
            
        }

        private void AssignPageDataRepository(FileInfo fileInfo)
        {
            switch (fileInfo.Extension)
            {
                case ".zip":
                case ".cbz":
                    PageRepository.Load(fileInfo);
                    break;
                case ".rar":
                case ".cbr":
                    break;
                default:
                    break;
            }
        }

        public List<PageData> List()
        {
            return PageRepository.PageData;
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }

    }
}
